<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>手机绑定</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/own.css"/>
    <script type="text/javascript" src="../../js/mui.min.js" ></script>
    <script type="text/javascript" src="../../js/common.js"></script>
    <script>
    	mui.init({
//		    subpages:[{
//		      url:'../commonback.html',
//		      id:'common.html',
//		      styles:{
//		        top:'0px',//mui标题栏默认高度为45px；
//		      }
//		    }]  
		  });   

		  var user_mobile=null;
		  mui.plusReady(function(){
		  	
		  	//初始化监听头部和底部事件
			tzdr.init.initHearListener();
  			
  			
		  	//获取手机号码
		  	user_mobile=mui.cacheUser.get("user_mobile");
		  	
		  	if(mui.isnull(user_mobile)){
		  		mui.toast("请重新登录");
		  		mui.openWindow("../login/login.html");
		  	}
		  	document.getElementById("oldPhone").value=user_mobile;
		  	document.getElementById("oldpassword").value="";
		  	document.getElementById("newpassword").value="";
		  	document.getElementById("newPhone").value="";
		  	document.getElementById("oldcode").addEventListener("tap",function(){
		  		  
		  		getoldCode();
		  	});
		  	
		  	document.getElementById("newcode").addEventListener("tap",function(){
		  		 
		  		getnewCode();
		  	});
		  	
		  	
		  	document.getElementById("pwSet").addEventListener("tap",function(){
		  		passwordSet();
		  	});
		  	
		  });
		  //获取原验证码
		  function getoldCode(){
		  	var paramUrl={
					url:"../login/login.html"
				}
		  	mui.app_request("user/security/send_sms",{
		  		"mobile":user_mobile,
				"type":1
		  	},function(result){
		  		mui.toast("发送成功！");
		  		var o=document.getElementById("oldcode");
		  		tzdr.smsTime(o);
		  		return;
		  	},function(result){
		  		
		  		if(result.code==2){
		  			mui.toast("短信验证码发送失败！");
		  			return;
		  		}else if(result.code==4){
		  			mui.toast("手机号码不存在！");
		  			return;
		  		}else if(result.code==5){
		  			mui.toast("操作过于频繁，请稍后再试！");
		  			return;
		  		}
		  	},paramUrl)
		  };
		  //获取新验证码
		  function getnewCode(){
			var oldPhone=document.getElementById("oldPhone").value;
		  	var newPhone=document.getElementById("newPhone").value;
		  	var paramUrl={
					url:"../login/login.html"
				}
		  	
		  	if(mui.isnull(newPhone)||!tzdr.validate_mobile(newPhone)){
		  		mui.toast("新手机号码不正确");
		  		return;
		  	}
		  	if(oldPhone==newPhone){
		  		mui.toast("手机号码已经注册");
		  		return;
		  	}
		  	
		  	
		  	mui.app_request("user/security/send_sms",{
		  		"mobile":newPhone,
				"type":3
		  	},function(result){
		  		mui.toast("发送成功！");
		  		var o=document.getElementById("newcode");
		  		tzdr.smsTime_new(o); 
		  		return;
		  	},function(result){
		  		if(result.code==2){
		  			mui.toast("短信验证码发送失败！");
		  			return;
		  		}else if(result.code==3){
		  			mui.toast("手机号码已经注册！");
		  			return;
		  		}else if(result.code==5){
		  			mui.toast("操作过于频繁，请稍后再试！");
		  			return;
		  		}	  		
		  	},paramUrl)
		  };
		  
		  
		  /**
			 * 短信倒计时 60s
			 * @param {Object} o  点击获取验证码对象
			 */
			var time_new=60;
			tzdr.smsTime_new=function(o){
				
			    if (time_new == 0) {  
			        o.removeAttribute("disabled");            
			        o.innerHTML="获取验证码";  
			        time_new = 60;
			        o.style.background="#d3413d";
			    } else {  
			        o.setAttribute("disabled", true);  
			        o.innerHTML="倒计时(" + time_new + ")";   
			        time_new--;  
			        o.style.background="rgb(211, 211, 211)";
			       setTimeout(function() {  
			            tzdr.smsTime_new(o);  
			        },  
			        1000)  
			    } 
			}
		  
		    
		  //修改提交
		  function passwordSet(){
		  	var oldCode=document.getElementById("oldpassword").value;
		  	var newCode=document.getElementById("newpassword").value;
		  	var newPhone=document.getElementById("newPhone").value;
		  	var paramUrl={
					url:"../login/login.html"
				}
		  	if(mui.isnull(newPhone)||!tzdr.validate_mobile(newPhone)){
		  		mui.toast("新手机号码不正确");
		  		return;
		  	}
		  	if(mui.isnull(oldCode)){
		  		mui.toast("原手机的短信验证码不能为空");
		  		return;
		  	}
		  	if(mui.isnull(newCode)){
		  		mui.toast("新手机的短信验证码不能为空"); 
		  		return;
		  	}

		  	mui.app_request("/user/security/upphone",{
		  		"oldCode":oldCode,
				"newMobile":newPhone,
				"newCode":newCode
		  	},function(result){
		  		mui.toast("修改成功！请使用新号码登录");
		  		mui.cacheUser.clear();
		  		plus.storage.removeItem("isRealName");
			    plus.storage.removeItem("inviteUrl"); 
		  		var lo=plus.webview.getWebviewById("login");
		  		if(lo){
		  			mui.app_refresh("login"); 
		  		}else{
		  			mui.openWindow("../login/login.html",'login');
		  		}
		  		
		  		return;
		  	},function(result){
		  		if(result.code==2){
		  			mui.toast("手机号码已经注册！");
		  			return;
		  		}else if(result.code==3){
		  			mui.toast("原验证码超时！");
		  			return;
		  		}else if(result.code==4){
		  			mui.toast("原验证码错误！");
		  			return;
		  		}else if(result.code==5){
		  			mui.toast("新验证码超时！");
		  			return;
		  		}else if(result.code==6){
		  			mui.toast("新验证码错误！");
		  			return;
		  		}else if(result.code==7){
		  			mui.toast("原验证码不能为空！");
		  			return;
		  		}else if(result.code==8){
		  			mui.toast("新验证码不能为空！");
		  			return;
		  		}else if(result.code==9){
		  			mui.toast("新手机号码不能为空！");
		  			return;
		  		}else{
		  			mui.toast("新手机号码格式错误！");
		  			return;
		  		}
		  	},paramUrl)
		  	
		  };
    </script>
</head>
<body>
	<header class="mui-bar mui-bar-nav own-topbg">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
		<h1 class="mui-title">修改手机号</h1>		
		<a href="javascript:void(0)" class="top-tel" id="online">在线客服</a>
	</header>
	<!--<nav class="navlist">
		<a href="javascript:void(0);" id="product">
			<span class="mui-icon mui-icon-list"></span>
			<span class="mui-tab-label">产品</span>
		</a>
		<a class="" href="javascript:void(0);"  id="scheme">
			<span class="mui-icon mui-icon-compose"></span>
			<span class="mui-tab-label">方案</span>
		</a>
		<a  class="navon"  id="account" href="javascript:void(0);">
			<span class="mui-icon mui-icon-contact mui-icon-icon-contact-filled"></span>
			<span class="mui-tab-label" >账户</span>
		</a>
	</nav>-->
<div class="mui-content ac_tel">
	<form class="mui-input-group">
		<div class="mui-input-row">
			<label>原号码</label>
			<input id="oldPhone" readonly="readonly" disabled="disabled"  type="tel" class="mui-input-clear mui-input" placeholder="">
		</div>
		<div class="mui-input-row">
			<label>验证码</label>
			<input id='oldpassword' type="tel" class="mui-input" placeholder="请输入验证码" maxlength="6" autocomplete="off">
			<button class="lg_codebtn" id="oldcode" type="button">获取验证码</button>
		</div>
	</form>	
	<form class="mui-input-group">
		<div class="mui-input-row">
			<label>新号码</label>
			<input id="newPhone"  type="tel" class="mui-input-clear mui-input" placeholder="" autocomplete="off">
		</div>
		<div class="mui-input-row">
			<label>验证码</label>
			<input id='newpassword' type="tel" class="mui-input" placeholder="请输入验证码" maxlength="6" autocomplete="off">
			<button class="lg_codebtn" id="newcode" type="button">获取验证码</button>
		</div>
	</form>
	<div class="mui-content-padded">
		<button class="mui-btn mui-btn-block lg-btnlogin" id="pwSet"  type="button">立即修改</button>
	</div>
	</div>
</body>
<script>
	tzdr.online();
</script>
</html>